package com.tree.thread;

/**
 * package com.tree.thread.pubsub
 * description: 死锁
 *
 * @author tree
 * @date 2019-12-05 15:06
 */
public class DeadLock {
    public static String s1 = "s1";
    public static String s2 = "s2";

    public static void main(String[] args) {
        new Thread(()->{
            while (true) {
                synchronized (s1) {
                    System.out.println(Thread.currentThread().getName() + "锁住s1");
                    synchronized (s2) {
                        System.out.println(Thread.currentThread().getName() + "锁住s2");
                    }
                }
            }
        },"thread1").start();

        new Thread(()->{
            while (true) {
                synchronized (s2) {
                    System.out.println(Thread.currentThread().getName() + "锁住s2");
                    synchronized (s1) {
                        System.out.println(Thread.currentThread().getName() + "锁住s1");
                    }
                }
            }
        },"thread2").start();
    }
}
